﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Timers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace Ramparts
{
    class WallAnimation : GameComponent
    {
        public bool isPlaying;
        private int currentx;
        private int currenty;
        private World world;
        private int currentCount;
        int updateDelay;
        int currentDelay;
        int stopCount;
        int length;

        public WallAnimation(int x, int y, World world)
        {
            currentx = x;
            currenty = y;
            this.world = world;
            isPlaying = true;
            currentCount = 0;
            currentDelay = updateDelay = 6;
            stopCount = 20;
            length = 7;
        }
    
        public void start()
        {
            isPlaying = true;
            currentCount = 0;
        }

        public void stop()
        {
            isPlaying = false;
        }
       
        public void update(GameTime gameTime)
        {
            
            if (currentDelay == 0 && isPlaying)
            {

                if (currentCount < length  && currentCount >= 0)
                    currentx++;
                if (currentCount < length * 2 && currentCount >= length)
                    currenty++;
                if (currentCount <  length * 3 && currentCount >= length * 2)
                    currentx--;
                if (currentCount < length * 4 && currentCount >= length * 3)
                    currenty--;

                world.wallLayer.SetTile(currentx, currenty, 2);
                world.CheckIfSurrounded();
                world.DrawPlayerMask();
                world.ConnectWalls();

                currentCount++;
                if (currentCount == stopCount)
                    stop();

                currentDelay = updateDelay;
            }
            else
            {
                currentDelay--;
            }

        }

    }
}
